package com.imut.lagain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.PreUpdate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * 最终答案之锁实体类
 */
@TableName("final_answer_lock")
public class FinalAnswerLock {
    private static final Logger log = LoggerFactory.getLogger(FinalAnswerLock.class);

    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField("lock_id")
    private String lockId;

    @TableField("user_id")
    private Long userId;

    @TableField("partner_id")
    private Long partnerId;

    @TableField("lock_name")
    private String lockName;

    @TableField("lock_description")
    private String lockDescription;

    @TableField("password_hash")
    private String passwordHash;

    @TableField("password_hint")
    private String passwordHint;

    @TableField("content_type")
    private String contentType;

    @TableField("content_data")
    private String contentData;

    @TableField("text_content")
    private String textContent;

    @TableField("file_content")
    private String fileContent;

    @TableField("file_path")
    private String filePath;

    @TableField("file_size")
    private Long fileSize;

    @TableField("unlock_date")
    private LocalDateTime unlockDate;

    @TableField("unlock_condition")
    private String unlockCondition;

    @TableField("status")
    private String status = "locked";

    @TableField("unlock_attempts")
    private Integer unlockAttempts = 0;

    @TableField("max_attempts")
    private Integer maxAttempts = 5;

    @TableField("last_attempt_time")
    private LocalDateTime lastAttemptTime;

    @TableField("unlock_time")
    private LocalDateTime unlockTime;

    @Column(name = "unlock_ritual_completed", nullable = false)
    private Boolean unlockRitualCompleted = false;

    @Column(name = "ritual_type", length = 50)
    private String ritualType;

    @Column(name = "ritual_config", columnDefinition = "JSON")
    private String ritualConfig;

    @Column(name = "reminder_enabled", nullable = false)
    private Boolean reminderEnabled = false;

    @Column(name = "reminder_time")
    private LocalDateTime reminderTime;

    @Column(name = "reminder_message", columnDefinition = "TEXT")
    private String reminderMessage;

    @Column(name = "share_token", length = 100)
    private String shareToken;

    @Column(name = "is_shared", nullable = false)
    private Boolean isShared = false;

    @Column(name = "share_expires_at")
    private LocalDateTime shareExpiresAt;

    @Column(name = "view_count", nullable = false)
    private Integer viewCount = 0;

    @Column(name = "last_viewed_at")
    private LocalDateTime lastViewedAt;

    @Column(name = "backup_enabled", nullable = false)
    private Boolean backupEnabled = true;

    @Column(name = "backup_frequency", length = 20)
    private String backupFrequency = "weekly";

    @Column(name = "last_backup_at")
    private LocalDateTime lastBackupAt;

    @Column(name = "encryption_level", nullable = false)
    private Integer encryptionLevel = 1;

    @Column(name = "tags", columnDefinition = "JSON")
    private String tags;

    @Column(name = "priority", nullable = false)
    private Integer priority = 1;

    @Column(name = "category", length = 50)
    private String category;

    @Column(name = "emotional_weight", nullable = false)
    private Integer emotionalWeight = 5;

    @Column(name = "unlock_emotion", length = 50)
    private String unlockEmotion;

    @Column(name = "pre_unlock_message", columnDefinition = "TEXT")
    private String preUnlockMessage;

    @Column(name = "post_unlock_message", columnDefinition = "TEXT")
    private String postUnlockMessage;

    @Column(name = "unlock_location", length = 200)
    private String unlockLocation;

    @Column(name = "unlock_weather", length = 100)
    private String unlockWeather;

    @Column(name = "unlock_mood", length = 50)
    private String unlockMood;

    @Column(name = "unlock_notes", columnDefinition = "TEXT")
    private String unlockNotes;

    @Column(name = "is_favorite", nullable = false)
    private Boolean isFavorite = false;

    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt = LocalDateTime.now();

    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt = LocalDateTime.now();

    @Column(name = "deleted_at")
    private LocalDateTime deletedAt;

    public FinalAnswerLock() {}

    public FinalAnswerLock(Long userId, String lockName, String lockDescription, String passwordHash, 
                          String passwordHint, LocalDateTime unlockDate) {
        this.userId = userId;
        this.lockName = lockName;
        this.lockDescription = lockDescription;
        this.passwordHash = passwordHash;
        this.passwordHint = passwordHint;
        this.unlockDate = unlockDate;
    }

    // Getters and Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getLockId() { return lockId; }
    public void setLockId(String lockId) { this.lockId = lockId; }

    public Long getUserId() { return userId; }
    public void setUserId(Long userId) { this.userId = userId; }

    public Long getPartnerId() { return partnerId; }
    public void setPartnerId(Long partnerId) { this.partnerId = partnerId; }

    public String getLockName() { return lockName; }
    public void setLockName(String lockName) { this.lockName = lockName; }

    public String getLockDescription() { return lockDescription; }
    public void setLockDescription(String lockDescription) { this.lockDescription = lockDescription; }

    public String getPasswordHash() { return passwordHash; }
    public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }

    public String getPasswordHint() { return passwordHint; }
    public void setPasswordHint(String passwordHint) { this.passwordHint = passwordHint; }

    public String getContentType() { return contentType; }
    public void setContentType(String contentType) { this.contentType = contentType; }

    public String getContentData() { return contentData; }
    public void setContentData(String contentData) { this.contentData = contentData; }

    public String getTextContent() { return textContent; }
    public void setTextContent(String textContent) { this.textContent = textContent; }

    public String getFileContent() { return fileContent; }
    public void setFileContent(String fileContent) { this.fileContent = fileContent; }

    public String getFilePath() { return filePath; }
    public void setFilePath(String filePath) { this.filePath = filePath; }

    public Long getFileSize() { return fileSize; }
    public void setFileSize(Long fileSize) { this.fileSize = fileSize; }

    public LocalDateTime getUnlockDate() { return unlockDate; }
    public void setUnlockDate(LocalDateTime unlockDate) { this.unlockDate = unlockDate; }

    public String getUnlockCondition() { return unlockCondition; }
    public void setUnlockCondition(String unlockCondition) { this.unlockCondition = unlockCondition; }

    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }

    public Integer getUnlockAttempts() { return unlockAttempts; }
    public void setUnlockAttempts(Integer unlockAttempts) { this.unlockAttempts = unlockAttempts; }

    public Integer getMaxAttempts() { return maxAttempts; }
    public void setMaxAttempts(Integer maxAttempts) { this.maxAttempts = maxAttempts; }

    public LocalDateTime getLastAttemptTime() { return lastAttemptTime; }
    public void setLastAttemptTime(LocalDateTime lastAttemptTime) { this.lastAttemptTime = lastAttemptTime; }

    public LocalDateTime getUnlockTime() { return unlockTime; }
    public void setUnlockTime(LocalDateTime unlockTime) { this.unlockTime = unlockTime; }

    public Boolean getUnlockRitualCompleted() { return unlockRitualCompleted; }
    public void setUnlockRitualCompleted(Boolean unlockRitualCompleted) { this.unlockRitualCompleted = unlockRitualCompleted; }

    public String getRitualType() { return ritualType; }
    public void setRitualType(String ritualType) { this.ritualType = ritualType; }

    public String getRitualConfig() { return ritualConfig; }
    public void setRitualConfig(String ritualConfig) { this.ritualConfig = ritualConfig; }

    public Boolean getReminderEnabled() { return reminderEnabled; }
    public void setReminderEnabled(Boolean reminderEnabled) { this.reminderEnabled = reminderEnabled; }

    public LocalDateTime getReminderTime() { return reminderTime; }
    public void setReminderTime(LocalDateTime reminderTime) { this.reminderTime = reminderTime; }

    public String getReminderMessage() { return reminderMessage; }
    public void setReminderMessage(String reminderMessage) { this.reminderMessage = reminderMessage; }

    public String getShareToken() { return shareToken; }
    public void setShareToken(String shareToken) { this.shareToken = shareToken; }

    public Boolean getIsShared() { return isShared; }
    public void setIsShared(Boolean isShared) { this.isShared = isShared; }

    public LocalDateTime getShareExpiresAt() { return shareExpiresAt; }
    public void setShareExpiresAt(LocalDateTime shareExpiresAt) { this.shareExpiresAt = shareExpiresAt; }

    public Integer getViewCount() { return viewCount; }
    public void setViewCount(Integer viewCount) { this.viewCount = viewCount; }

    public LocalDateTime getLastViewedAt() { return lastViewedAt; }
    public void setLastViewedAt(LocalDateTime lastViewedAt) { this.lastViewedAt = lastViewedAt; }

    public Boolean getBackupEnabled() { return backupEnabled; }
    public void setBackupEnabled(Boolean backupEnabled) { this.backupEnabled = backupEnabled; }

    public String getBackupFrequency() { return backupFrequency; }
    public void setBackupFrequency(String backupFrequency) { this.backupFrequency = backupFrequency; }

    public LocalDateTime getLastBackupAt() { return lastBackupAt; }
    public void setLastBackupAt(LocalDateTime lastBackupAt) { this.lastBackupAt = lastBackupAt; }

    public Integer getEncryptionLevel() { return encryptionLevel; }
    public void setEncryptionLevel(Integer encryptionLevel) { this.encryptionLevel = encryptionLevel; }

    public String getTags() { return tags; }
    public void setTags(String tags) { this.tags = tags; }

    public Integer getPriority() { return priority; }
    public void setPriority(Integer priority) { this.priority = priority; }

    public String getCategory() { return category; }
    public void setCategory(String category) { this.category = category; }

    public Integer getEmotionalWeight() { return emotionalWeight; }
    public void setEmotionalWeight(Integer emotionalWeight) { this.emotionalWeight = emotionalWeight; }

    public String getUnlockEmotion() { return unlockEmotion; }
    public void setUnlockEmotion(String unlockEmotion) { this.unlockEmotion = unlockEmotion; }

    public String getPreUnlockMessage() { return preUnlockMessage; }
    public void setPreUnlockMessage(String preUnlockMessage) { this.preUnlockMessage = preUnlockMessage; }

    public String getPostUnlockMessage() { return postUnlockMessage; }
    public void setPostUnlockMessage(String postUnlockMessage) { this.postUnlockMessage = postUnlockMessage; }

    public String getUnlockLocation() { return unlockLocation; }
    public void setUnlockLocation(String unlockLocation) { this.unlockLocation = unlockLocation; }

    public String getUnlockWeather() { return unlockWeather; }
    public void setUnlockWeather(String unlockWeather) { this.unlockWeather = unlockWeather; }

    public String getUnlockMood() { return unlockMood; }
    public void setUnlockMood(String unlockMood) { this.unlockMood = unlockMood; }

    public String getUnlockNotes() { return unlockNotes; }
    public void setUnlockNotes(String unlockNotes) { this.unlockNotes = unlockNotes; }

    public Boolean getIsFavorite() { return isFavorite; }
    public void setIsFavorite(Boolean isFavorite) { this.isFavorite = isFavorite; }

    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }

    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }

    public LocalDateTime getDeletedAt() { return deletedAt; }
    public void setDeletedAt(LocalDateTime deletedAt) { this.deletedAt = deletedAt; }

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
}